package hos.demo

import android.location.GnssStatus
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import hos.demo.databinding.ActivityTrainBinding
import hos.http.HttpCallback
import hos.http.HttpConfig
import hos.http.HttpRequest
import hos.okhttp.convert.HttpResponseMapListConvert

class SoapTrainActivity : AppCompatActivity() {
    private val activityMainBinding by lazy { ActivityTrainBinding.inflate(layoutInflater) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(activityMainBinding.root)
        GnssStatus.CONSTELLATION_BEIDOU
        activityMainBinding.btn1.setOnClickListener {
            App.train().stationName
                .convert(HttpResponseMapListConvert())
                .enqueue<String>(object : HttpCallback<String>() {
                    override fun onSuccess(request: HttpRequest<*>?, response: String?) {
                        Log.i("Http", "Text$response");
                        Toast.makeText(
                            this@SoapTrainActivity,
                            response.toString(),
                            Toast.LENGTH_SHORT
                        )
                            .show()
                    }

                    override fun onFailed(throwable: Throwable?) {
                        throwable?.printStackTrace()
                    }

                })
        }
        activityMainBinding.btn2.setOnClickListener {
            HttpConfig.runIo {
                val result = App.train()
                    .stationNameDataSet
                    .convert(HttpResponseMapListConvert())
                    .dialog(true, this).asString()
                Log.d("TAG", "delay: $result")
                runOnUiThread {
                    Toast.makeText(this@SoapTrainActivity, result.toString(), Toast.LENGTH_SHORT)
                        .show()
                }
            }
        }
        activityMainBinding.btn3.setOnClickListener {
            App.train().versionTime
                .convert(HttpResponseMapListConvert())
                .enqueue<String>(object : HttpCallback<String>() {
                    override fun onSuccess(
                        request: HttpRequest<*>?,
                        response: String?
                    ) {
                        Log.i("Http", "Game" + response.toString());
                        Toast.makeText(
                            this@SoapTrainActivity,
                            response.toString(),
                            Toast.LENGTH_SHORT
                        )
                            .show()
                    }

                    override fun onFailed(throwable: Throwable?) {
                        throwable?.printStackTrace()
                    }

                })
        }
        activityMainBinding.btn4.setOnClickListener {
            App.tianJing().getCommonType("LawRecordInspectionResults")
                .convert(HttpResponseMapListConvert())
                .enqueue<MutableList<MutableMap<String, Any>>>(object : HttpCallback<MutableList<MutableMap<String, Any>>>() {
                    override fun onSuccess(
                        request: HttpRequest<*>?,
                        response: MutableList<MutableMap<String, Any>>?
                    ) {
                        Log.i("Http", "Game" + response.toString());
                        Toast.makeText(
                            this@SoapTrainActivity,
                            response.toString(),
                            Toast.LENGTH_SHORT
                        )
                            .show()
                    }

                    override fun onFailed(throwable: Throwable?) {
                        throwable?.printStackTrace()
                    }

                })
        }
        activityMainBinding.btn5.setOnClickListener {
            HttpConfig.runIo {
                val response = App.tianJing().getCommonType("LawRecordInspectionResults")
                    .convert(HttpResponseMapListConvert())
                    .execute<MutableList<MutableMap<String, Any>>>()
                runOnUiThread {
                    Log.i("Http", "Game" + response.toString());
                    Toast.makeText(
                        this@SoapTrainActivity,
                        response.toString(),
                        Toast.LENGTH_SHORT
                    )
                        .show()
                }

            }

        }
    }
}